//menu
 $(document).ready(function(){
 	$('.nav li').each(function(){
 		$(this).hover(
 			function() {
 				$(this).children('div.subnav').animate({
				   height: 'toggle', opacity: 'toggle'
				 }, "fast"); 
 			},
 			function() {
 				$(this).children('div.subnav').hide();
 			}
 		);
	 })
	 
 });






function loadBgImage(){
	var img = new Image();
	img.src = "/media/static/images/all.png";
}

function showPopup(){
  var popupLayer = $("#layer-popup");
  changePopupPostion();
  if($.browser.msie && $.browser.version == "6.0"){
		window.onresize = window.onscroll = function(){
			changePopupPostionForIE6();
		};
  }
}

function addWindowLoadEvent(func){
	var oldonload = window.onload;  
	if (typeof window.onload != 'function') {  
		window.onload = func;  
	} else {    
		window.onload = function() {  
			oldonload();  
			func();
		}  
	}
}

// animation

function showBoxH(speed){
	var $cur = 1;
	var $i = 1;
	var $len = $('.animation-h-box .showbox-h>ul>li').length;
	var $pages = Math.ceil($len / $i);
	var $w = $('.animation-h-box').width();
	var $showbox = $('.showbox-h');
	var $num = $('.scroll-paging .num li')
	var $pre = $('.showbox-h-left')
	var $next = $('.showbox-h-right');
	var $speed = speed;
	//向前滚动
	$pre.click(function(){
		if (!$showbox.is(':animated')) { 
			if ($cur == 1) { 
			$showbox.animate({
				left: '-=' + $w * ($pages - 1)
			}, $speed); 
			$cur = $pages; 
		}
		else {
			$showbox.animate({
				left: '+=' + $w
			}, $speed); 
			$cur--; 
		}
		$num.eq($cur - 1).addClass('numcur').siblings().removeClass('numcur'); 
	}
	});
	//向后滚动
	$next.click(function(){
		if (!$showbox.is(':animated')) { 
			if ($cur == $pages) { 
				$showbox.animate({
					left: 0
				}, $speed); 
			$cur = 1; 
		}
		else {
			$showbox.animate({
				left: '-=' + $w
			}, $speed);
			$cur++; 
		}
		bindAnimationImgs($cur);
		$num.eq($cur - 1).addClass('numcur').siblings().removeClass('numcur'); 
	}
	});
	//数字点击事件
	$num.click(function(){
		if (!$showbox.is(':animated')) { 
			var $index = $num.index(this); 
			$showbox.animate({
				left: '-' + ($w * $index)
			}, $speed);
			$cur = $index + 1; 
			bindAnimationImgs($cur);
		$(this).addClass('numcur').siblings().removeClass('numcur'); 
	}
	});
	var _moving;
	var $boxes = $showbox.add($num).add($pre).add($next);
	$boxes.mouseover(function(){
		clearInterval(_moving);
	}).mouseout(function(){
		_moving=setInterval(function(){
			$next.click();
		},6000);
	});
	$showbox.trigger('mouseout');
}

function showBoxV(speed){
	var _wrap=$('#discount-box');
	var _interval=speed;
	var _moving;
	_wrap.hover(function(){
			clearInterval(_moving);
		},function(){
				_moving=setInterval(function(){
				var _field=_wrap.find(".app-box-basic-small:first");
				var _h=_field.height();
				_field.animate({marginTop:-_h+'px'},600,function(){
				_field.css('marginTop',0).appendTo(_wrap);
			})
		},_interval)
	}).trigger('mouseleave');
}

function showNotice(speed){
	var _wrap=$('.notice-list-content ul');
	var _interval=speed;
	var _moving;
	$("#notice-board").hover(function(){
			clearInterval(_moving);
		},function(){
				_moving=setInterval(function(){
				var _field=_wrap.find("li:first");
				var _h=_field.width();
				_field.animate({marginLeft:-_h+'px'},600,function(){
				_field.css('marginLeft',0).appendTo(_wrap);
			})
		},_interval)
	}).trigger('mouseleave');
	
	var _next = $(".notice-board-more");
	_next.click(function(){
		var _field=_wrap.find("li:first");
		var _h=_field.width();
		_field.animate({marginLeft:-_h+'px'},600,function(){
			_field.css('marginLeft',0).appendTo(_wrap);
		});
	});
}

//Pre Loading Images
function hideVerticalAppsImages(con){
	var items = $("#" + con + " .app-logo-mid");
	var imgs = new Array();
	$.each(items,function(i){
		items[i] = $(items[i]);										
		imgs.push(items[i].css("background-image"));	
		items[i].css("background","none");
	});
	$("#" + con).data("imgs",imgs);
}

function bindAnimationImgs(pageNum){
	var page = $(".animation-h-box .showbox-h li")[pageNum - 1];
	var logos = $(page).find(".app-logo-big");
	if("none" != logos.css("background-image")){
		return;
	}
	$.each(logos,function(i){
		$(this).attr("style",$(this).attr("original"));
	});
}

